package com.weiyuwqj.server.service.asset.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.SysAssetDeposit;
import com.weiyuwqj.api.model.vo.SysAssetDepositVo;
import com.weiyuwqj.api.service.SysAssetDepositService;
import com.weiyuwqj.server.mapper.SysAssetDepositMapper;
import com.weiyuwqj.server.service.base.BaseServiceImpl;

/**
 * 
 * @className:SysAssetDepositServiceImpl	
 * @Description: 资产方押金
 * @author cx
 * @date:2017年3月29日上午10:45:27 
 *
 */
@Service("sysAssetDepositService")
public class SysAssetDepositServiceImpl extends BaseServiceImpl<SysAssetDeposit> implements SysAssetDepositService{

	@Autowired
	private SysAssetDepositMapper  sysAssetDepositMapper;
	
	@Override
	public PageList getPageList(final Paginator p,final Map<String, Object> param) {
		PageHelper.startPage(p.getPageNum(), p.getPageSize());
		List<SysAssetDepositVo> list = this.sysAssetDepositMapper.getList(param);
		return new PageList(list);
	}
	
	@Override
	public SysAssetDeposit findById(final Integer id) {
		return this.sysAssetDepositMapper.findById(id);
	}
	
	@Override
	public SysAssetDeposit findByCompanyId(final Integer companyId){
		final List<SysAssetDeposit> list = this.sysAssetDepositMapper.findByCompanyId(companyId);
		if(list!=null&&!list.isEmpty()){
			return list.get(0);
		}
		return null;
	}
	
	@Override
	public int updateByAmount(final Integer companyId,final double amount){
		final HashMap<String,Object> map = new HashMap<String, Object>();
		map.put("companyId", companyId);
		map.put("amount", amount);
		return this.sysAssetDepositMapper.updateByAmount(map);
	}

}
